package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.pojo.RoleMenu;
import com.example.mapper.RoleMenuMapper;
import com.example.service.IRoleMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.vo.ResultVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 角色菜单表 服务实现类
 * </p>
 *
 * @author wsl
 * @since 2022-03-27
 */
@Service
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu> implements IRoleMenuService {

    @Override
    @Transactional
    public ResultVo updateRoleMenu(RoleMenu roleMenu) {
        //1、删除之前的角色菜单
        baseMapper.delete(new QueryWrapper<RoleMenu>().eq("role_id",roleMenu.getRoleId()));
        roleMenu.getMenuList().forEach(menuId->{
            RoleMenu newRoleMenu = new RoleMenu().setMenuId(menuId).setRoleId(roleMenu.getRoleId());
            baseMapper.insert(newRoleMenu);
        });
        return ResultVo.ok();
    }
}
